package com.microbroadcast.DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.microbroadcast.resource.Area;

public class AreaPersistence {

	public static Area getArea(long areaID) {
		Area result = null;
		try {
			Connection c = DBHelper.getConnection();
			String sql = "select * from area where AreaID = ?";
			PreparedStatement ps = c.prepareStatement(sql);
			ps.setLong(1, areaID);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				String areaName = rs.getString("AreaName");
				int provinceID = rs.getInt("ProvinceID");
				String province = ProvincePersistence.getProvince(provinceID);
				int cityID = rs.getInt("CityID");
				String city = CityPersistence.getCity(cityID);
				String country = rs.getString("Country");
				result = new Area(areaID, areaName, province, city, country);
			}
			rs.close();
			ps.close();
			c.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return result;
	}

}
